﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Sql;
using System.Data.SqlClient;

namespace KaoWuYou.Models
{
    public class TestedPaperModel
    {
        public List<string> Answers
        { set; get; }
        [Required]
        public int Mark
        { set; get; }
        [Required]
        public WebUserModel TestTaker
        { set; get; }
        [Required]
        public TestPaperModel TestPaper
        { set; get; }
        [Required]
        public int TestPaperID
        { set; get; }

        public void SaveTestedPaper()
        {
            SqlConnection conn = new SqlConnection(Systems.ConnString);
            SqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = @"INSERT INTO TestedPaper(Answers,Mark,TestTaker,TestPaperID) 
                 VALUES(@Answers,@Mark,@TestTaker,@TestPaperID)  ";
            cmd.Parameters.AddRange(new SqlParameter[]
                    {
                        new SqlParameter("@Answers",Answers),
                        new SqlParameter("@Mark",Mark),
                        new SqlParameter("@TestTaker",TestTaker),
                        new SqlParameter("@TestPaperID",TestPaperID),
                    });
            cmd.ExecuteNonQuery();
            conn.Close();
        }
    }
}